//Current version: 0.05

include('shared.lua')
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

ENT.Base = "base_entity"
ENT.Type = "brush"

function ENT:Initialize()
	self:SetNoDraw(true)
	self:SetCollisionGroup(COLLISION_GROUP_NONE)
end

function ENT:StartTouch(ent)
	local class = ent:GetClass()
	if class == "npc_citizen" then
		self:SetNWInt("Citiizens", (self:GetNWInt("Citizens") + 1)
	elseif class == "npc_combine_s" then
		self:SetNWInt("Combine", (self:GetNWInt("Combine") + 1)
	elseif ent:IsPlayer() then
		self:SetNWInt("Citizens", (self:GetNWInt("Citizens") + 1)
	end
end

function ENT:Touch()
end

function ENT:EndTouch(ent)
	local class = ent:GetClass()
	if class == "npc_citizen" then
		self:SetNWInt("Citiizens", (self:GetNWInt("Citizens") - 1)
	elseif class == "npc_combine_s" then
		self:SetNWInt("Combine", (self:GetNWInt("Combine") - 1)
	elseif ent:IsPlayer() then
		self:SetNWInt("Citizens", (self:GetNWInt("Citizens") - 1)
	end
end

function ENT:Think()
	local dlight = DynamicLight( self:EntIndex() )
	if not ( dlight ) then
		dlight:Spawn()
	end
	if ( dlight ) then
		dlight.Pos = self:OBBCenter()
		dlight.r = self:GetNWInt("CombineIn", 0) >= self:GetNWInt("RebelsIn") and 255 or 0
		dlight.g = self:GetNWInt("RebelsIn", 0) >= self:GetNWInt("CombineIn") and 255 or 0
		dlight.b = 0
		dlight.Brightness = 255
		dlight.Size = 256
		dlight.Decay = dlight.Size * 5
		dlight.DieTime = CurTime() + 1
	end
end